package cn.kshost.zqyg.manager.controller;

import cn.kshost.zqyg.manager.service.BrandCategoryService;
import cn.kshost.zqyg.manager.service.BrandService;
import cn.kshost.zqyg.model.dto.product.CategoryBrandDto;
import cn.kshost.zqyg.model.entity.product.Brand;
import cn.kshost.zqyg.model.entity.product.CategoryBrand;
import cn.kshost.zqyg.model.vo.common.Result;
import cn.kshost.zqyg.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/admin/product/brandCategory")
public class BrandCategoryController {

    @Autowired
    BrandCategoryService brandCategoryService;

    @Operation(summary = "条件品牌分类分页查询")
    @GetMapping("/{pageNum}/{pageSize}")
    public Result<PageInfo<CategoryBrand>> getBrandCategoryPageList(@PathVariable int pageNum, @PathVariable int pageSize, CategoryBrandDto  categoryBrandDto) {
        PageInfo<CategoryBrand> pageInfo =  brandCategoryService.getBrandCategoryByPage(pageNum,pageSize,categoryBrandDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "新增品牌分类")
    @PostMapping("/addCategoryBrand")
    public Result<String> addBrandCategory(@RequestBody CategoryBrandDto categoryBrandDto) {
        brandCategoryService.addBrandCategory(categoryBrandDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "修改品牌分类")
    @PutMapping("/modifyCategoryBrand")
    public Result<String> modifyBrandCategory(@RequestBody CategoryBrandDto categoryBrandDto) {
        brandCategoryService.modifyBrandCategory(categoryBrandDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "根据id删除品牌分类")
    @DeleteMapping("/removeCategoryBrand")
    public Result<String> removeBrandCategory(@RequestBody CategoryBrandDto categoryBrandDto) {
        brandCategoryService.removeBrandCategory(categoryBrandDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "根据用户分类id查询对应商品列表")
    @GetMapping("/findBrandByCategoryId/{categoryId}")
    public Result<List<CategoryBrand>> findBrandByCategoryId(@PathVariable int categoryId) {
       List<Brand> brandList =   brandCategoryService.findBrandByCategoryId(categoryId);
       return  Result.build(brandList, ResultCodeEnum.SUCCESS);

    }
}
